
Chapter B2. L2CAP Echoing

From:
  Killer Game Programming in Java 

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat Yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th

  Web Site for the book: http://fivedots.coe.psu.ac.th/~ad/jg


If you use this code, please mention my name, and include a link
to the book's Web site.

**NOTE**: this chapter is NOT in the hardcopy book printed by O'Reilly.

Thanks,
  Andrew


============================

This chapter describes TWO client/server applications using the
Bluetooth API in JSR 82, which is available in version 2.2. 
of the J2ME Wireless Toolkit (WTK22). It can be downloaded from 
http://java.sun.com/products/j2mewtoolkit/

The first client/server application involves two MIDlets --
the server code is in the EchoLServerMIDlet\ directory,
the client code in EchoLClientMIDlet\.

The second client/server application involves two MIDlets --
the server code is in the EchoLPServerMIDlet\ directory (note the 'P'),
and the _same_ client code as before, in EchoLClientMIDlet\.

In summary, you should see three subdirectories here:
  EchoLClientMIDlet\
  EchoLPServerMIDlet\
  EchoLServerMIDlet\

============================

The first Server MIDlet (in EchoLServerMIDlet\)

The first Echo Server MIDlet consists of 5 Java files:
   EchoLServerMIDlet.java, ScrollableMessagesBox.java, 
   KeyRepeatTask.java, EchoLServer.java, 
   ThreadedEchoLHandler.java

------
Server Compilation and Execution (using WTK22's KToolbar)

Create a new project called EchoLServerMIDlet, with the MIDlet
class name EchoLServerMIDlet.

Make sure to select the "Bluetooth/OBEX for J2ME (JSR 82)" API
in the project's API settings.

Copy the Java files to WTK22\apps\EchoLServerMIDlet\src\ 

Build and run (but see "Server Notes" at the end)


============================

The second Server MIDlet (in EchoLPServerMIDlet\)

The second Echo Server MIDlet consists of 6 Java files:
   EchoLPServerMIDlet.java, ScrollableMessagesBox.java, 
   KeyRepeatTask.java, EchoLPServer.java, 
   ConnectionsHandler.java, ClientInfo.java

------
Server Compilation and Execution (using WTK22's KToolbar)

Create a new project called EchoLPServerMIDlet, with the MIDlet
class name EchoLPServerMIDlet.

Make sure to select the "Bluetooth/OBEX for J2ME (JSR 82)" API
in the project's API settings.

Copy the Java files to WTK22\apps\EchoLPServerMIDlet\src\ 

Build and run (but see "Server Notes" at the end)

============================

The Client MIDlet (in EchoLClientMIDlet\)

The Echo Client MIDlet consists of 5 Java files:
   EchoLClientMIDlet.java, ServiceFinder.java, ServicesList.java, 
   ClientForm.java, EchoLClient.java

and one image file:
   Icon.png

------
Client Compilation and Execution (using WTK22's KToolbar)

Create a new project called EchoLClientMIDlet, with the MIDlet
class name EchoLClientMIDlet.

Make sure to select the "Bluetooth/OBEX for J2ME (JSR 82)" API
in the project's API settings.

Copy the Java files to WTK22\apps\EchoLClientMIDlet\src\ 
Copy the image files to WTK22\apps\EchoLClientMIDlet\res\ 

Build and run (but see "Client Notes" below)

------

Client Notes

Start the server before starting any clients.

EchoLClientMIDlet can be the client for EchoLServerMIDlet
or EchoLPServerMIDlet.

Client MIDlets should be run in a separate invocation of 
WTK22 from the server MIDlet. 

I've only been able to start a maximum of two clients before 
socket, security, or JSR 82 initialization errors occur. 

When a problem appears, the WTK22 invocations for the 
client _and_ server need to be restarted.

---------

Server Notes

Since many clients will be connected to the server, it may be necessary
to increase the Bluetooth "bluetooth.connected.devices.max" setting
which specifies the maximum number of connections to a device.

WTK22's value for "bluetooth.connected.devices.max" 
can be set in the "System Properties" tab of the "Bluetooth/OBEX" tab 
in the "Preferences" menu. Increase it to 3 to allow a maximum of
three clients to be connected to the server at once.

---------

Last updated: 13th September 2005
